﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using HF.BizWinner.DB.Linq;
using HF.BizWinner.DB.Authority;
using HF.BizWinner.Lib.Util;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        
    }

    protected void BtnLogin_Click(object sender, ImageClickEventArgs e)
    {
        string in_username = this.UserName.Text;
        string in_password = this.Password.Text;
        string in_code = this.RandomCode.Text.ToLower();
        string session_code = (new RandomCode()).GetFormSession().ToLower();

        if (!in_code.Equals(session_code))
        {
            this.HintMessage.Text = "验证码输入有误！";
            return;
        }

        var user = from u in (new BizWinnerDataContext()).User
                   where u.UserName == in_username && u.Password == in_password
                   select u;
        if (user.Count() == 1)
        {
            UserAuthority.SetLoginUser(user.First());
            this.HintMessage.Text = "成功登陆！";
            Response.Redirect("Mapframe.aspx");
        }
        else
        {
            this.HintMessage.Text = "用户名密码错误！";
        }
    }
}
